package com.ssh;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

public class LengthOfLongestSubstring1_3 {
	public static void main(String[] args) {
			int a = lengthOfLongestSubstring("abbcd");
		//	int b = lengthOfLongestSubstring("bbbb");
			SimpleDateFormat formatter = new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss:SSS");
			String formatStr =formatter.format(new Date());
			System.out.println(formatStr);
			//int c = lengthOfLongestSubstring(a);
		//	System.out.println(a);
		//	System.out.println(b);
			System.out.println(a);
			String formatStr1 =formatter.format(new Date());
			System.out.println(formatStr1);
		}
	/**
	 * 求最长的不重复的字符串
	 * 通过一个类似指针的变量来控制重复字母出现后的今进度，只增不减
	 * @param s
	 * @return
	 */
	public static int lengthOfLongestSubstring (String s) {
		Map<Character, Integer> map = new HashMap<Character, Integer>();
		int N = s.length();
		int lo = 0,max = 0;
		for (int i = 0; i < N; i++) {
			char c = s.charAt(i);
			if (map.containsKey(c)) {
				lo = (map.get(c)+1)>lo?(map.get(c)+1):lo;
				System.out.println("lo = "+lo);
			}
			map.put(c, i);
			max = (i-lo+1)>max?(i-lo+1):max;
			System.out.println("max = "+max);
		}
 		return max;
	}
}
